/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.ohosadvance.tsnackbar;

import ohos.agp.components.AttrSet;
import ohos.agp.components.Button;
import ohos.agp.components.element.Element;
import ohos.agp.components.element.ElementScatter;
import ohos.agp.components.element.PixelMapElement;
import ohos.agp.components.element.VectorElement;

import ohos.app.Context;

/**
 * description :
 *
 * @since : 2021/7/12
 */
public class BGButton extends Button {
    public BGButton(Context context) {
        this(context, null);
    }

    public BGButton(Context context, AttrSet attrSet) {
        this(context, attrSet, "");
    }

    public BGButton(Context context, AttrSet attrSet, String styleName) {
        super(context, attrSet, styleName);
        Element element = ElementScatter.getInstance(mContext).parse(ResourceTable.Graphic_btn_ripple_bg);
        setButtonsRippleColor(element);
    }

    /**
     * setButtonsRippleColor
     *
     * @param element element
     */
    public void setButtonsRippleColor(Element element) {
        Element resultElement = null;
        if (element instanceof PixelMapElement) {
            resultElement = (PixelMapElement) element;
        } else if (element instanceof VectorElement) {
            resultElement = (VectorElement) element;
        } else {
            resultElement = element;
        }
        setBackground(resultElement);
    }
}
